package com.jianhua.backend.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/**
 * <p>
 * 记录订单中包含的具体菜品或套餐
 * </p>
 *
 * @author author
 * @since 2025-07-02
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
@TableName("order_items")
public class OrderItems implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 明细项ID
     */
    @TableId(value = "item_id", type = IdType.AUTO)
    private Integer itemId;

    /**
     * 关联订单ID
     */
    @TableField("order_id")
    private Integer orderId;

    /**
     * 项目类型（dish单品/package套餐）
     */
    @TableField("item_type")
    private String itemType;

    /**
     * 关联菜品ID（当item_type=dish时）
     */
    @TableField("dish_id")
    private Integer dishId;

    /**
     * 关联套餐ID（当item_type=package时）
     */
    @TableField("package_id")
    private Integer packageId;

    /**
     * 数量
     */
    @TableField("quantity")
    private Integer quantity;

    /**
     * 单价
     */
    @TableField("unit_price")
    private BigDecimal unitPrice;

    /**
     * 总价
     */
    @TableField("total_price")
    private BigDecimal totalPrice;

    /**
     * 特殊要求
     */
    @TableField("special_requests")
    private String specialRequests;
    // 已有内容不变，添加以下构造方法便于快速构建订单项
    public OrderItems(Integer orderId, Integer dishId, Integer quantity, BigDecimal unitPrice) {
        this.orderId = orderId;
        this.itemType = "dish";
        this.dishId = dishId;
        this.quantity = quantity;
        this.unitPrice = unitPrice;
        this.totalPrice = unitPrice.multiply(BigDecimal.valueOf(quantity));
        this.specialRequests = ""; // 可选，默认空字符串
    }

}
